package com.bonc.controller;

import com.bonc.entity.ParkCompany;
import com.bonc.service.ParkCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 努力！奋斗！
 * 理解的快不等于理解的好！
 *
 * @author LRJ
 * @Date 2021/08/02  8:56
 **/
@Api(value = "ParkCompanyController", description = "企业画像")
@RestController
@Slf4j
public class ParkCompanyController {

    @Resource
    private ParkCompanyService parkCompanyService;

    /**
     * 高级查询并且分页
     * @param parkCompany
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(notes = "高级查询公司信息并且分页", value = "高级查询公司信息并且分页", response = ParkCompany.class, httpMethod = "POST")
    @PostMapping("/queryParCompany")
    public @ResponseBody
    List<ParkCompany> queryParCompany(@RequestBody @RequestParam(value = "parkCompany",required = false) ParkCompany parkCompany,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "2") Integer pageSize) {
        List<ParkCompany> parkCompanies = parkCompanyService.queryParCompany(parkCompany, pageNum, pageSize);
        log.info("这页数据的数目为:{}", parkCompanies.size());
        log.info("当前页为:{}", pageNum);
        log.info("一页的尺寸为:{}", pageSize);
        return parkCompanies;
    }

    /**
     * 查看详情(根据id查询数据)
     *
     * @param id
     * @return
     */
    @ApiOperation(notes = "查看详情(根据id查询数据)", value = "查看详情(根据id查询数据)", response = ParkCompany.class, httpMethod = "GET")
    @GetMapping("/findParkCompanyById")
    public @ResponseBody
    ParkCompany findById(String id) {
        return parkCompanyService.findById(id);
    }

    /**
     * 获取企业新增数目或者增长率
     *
     * @param year 年份
     * @param rate 是否取得增长率(0是增长率  1只是新增数量) 默认为新增数目
     * @return
     */
    @ApiOperation(notes = "获取企业新增数目或者增长率", value = "获取企业新增数目或者增长率", response = Double.class, httpMethod = "GET")
    @GetMapping("/getGrowthRate")
    public @ResponseBody
    Double getGrowthRate(@RequestParam(value = "year", defaultValue = "0") Integer year,
                         @RequestParam(value = "rate", defaultValue = "1") Integer rate) {
        Double growthRate = parkCompanyService.getGrowthRate(year, rate);
        if (year == 0) {
            log.info("当前年份是:今年");
        } else {
            log.info("当前年份是:{}", year);
        }
        if (rate == 1) {
            log.info("新增数目为:{}", growthRate);
        } else {
            log.info("增长率为:{}", growthRate);
        }
        return growthRate;
    }
    @ApiOperation(notes = "获取企业数目增长率", value = "获取企业数量增长率", httpMethod = "GET")
    @GetMapping("/findComponyIncreaseRate")
    public @ResponseBody
    List<Map<String,Object>> findComponyIncreaseRate() {
        List<Map<String,Object>> list=parkCompanyService.findComponyIncreaseRate();
        return list;
    }

    @GetMapping("/findRegisteredCapital")
    @ApiOperation(notes ="查询各种类型公司所占比例", value="查询各种类型公司所占比例",httpMethod="GET")
    public @ResponseBody
    List<Map<String,String>> findRegisteredCapital(){
        List<Map<String,String>> parkCompanies=parkCompanyService.findRegisteredCapital();

        return parkCompanies;
    }




}
